package csce315.group10.androidapp;

import java.io.File;

import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;

import csce315.group10.R;
import csce315.group10.yearbook.tinymsg.C2DMClientActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;

public class MainMenu extends Activity {
	
	/* private instance variables */
	public CustomApp appState;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mainmenu);
        appState = ((CustomApp)getApplicationContext());
    }
    
    /* Button Click Handler for opening the photo viewer */
    public void openPhotoViewer(View v){  
    	Intent intent = new Intent();
    	intent.setClass(this,photoViewer.class);
    	startActivity(intent);
    }
    
    /* Button Click Handler for opening the contact list */
    public void openContactList(View v){  
    	Intent intent = new Intent();
    	intent.setClass(this,ContactList.class);
    	/* Display list of contacts */
    	startActivity(intent);
    }
    
    /* Button Click Handler for opening the event list */
    public void openEventList(View v){  
    	Intent intent = new Intent();
    	intent.setClass(this,EventList.class);
    	/* Display list of events */
    	startActivity(intent);
    }
    
    /* Button Click Handler for opening the client*/
    public void openClient(View v){  
    	Intent intent = new Intent();
    	intent.setClass(this,TopicList.class);
    	/* Display list of Topics */
    	startActivity(intent);
    }
    /* Button Click Handler for opening the potential story list */
    public void openStoryList(View v){  
    	Intent intent = new Intent();
    	intent.setClass(this,PotentialStoryList.class);
    	/* Display list of potential stories */
    	startActivity(intent);
    }
    
    /* create menu */
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    	/* only create menu with create and delete options if the user is Editor and Chief */
    	if(appState.get_current_user().get_position().equals("Editor And Chief")){
	        MenuInflater inflater = getMenuInflater();
	        inflater.inflate(R.menu.mainmenu_menu, menu);
	        return true;
    	}
    	return false;
    }
    
    /* set actions for when menu items are selected */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.change_password:     	changePassword();
            								break;
            case R.id.logout:				logout();
            								break;
        }
        return true;
    }
    
    /* start the dialog to get new contact info */
    private void changePassword(){
    	Intent intent = new Intent();
    	intent.setClass(this,ChangePasswordDialog.class);
    	startActivity(intent);
    }
    /* logout */
    private void logout(){
    	Intent intent = new Intent();
    	intent.setClass(this,YearBookAppActivity.class);
    	startActivity(intent);
    	finish();
    }
}